<template>
  <div>
    <detail-banner
      :gallaryImgs="gallaryImgs"
      :sightName="sightName"
      :bannerImg="bannerImg"
    ></detail-banner>
    <detail-header></detail-header>
    <div class="kong">
      <detail-list :list="list"></detail-list>
    </div>
  </div>
</template>

<script>
import DetailBanner from "./components/banner.vue";
import DetailHeader from "./components/header.vue";
import DetailList from "./components/list.vue";
import axios from "axios";

export default {
  name: "Detail",
  components: {
    DetailBanner,
    DetailHeader,
    DetailList,
  },
  data() {
    return {
      sightName: "",
      bannerImg: "",
      gallaryImgs: [],
      list: [],
    };
  },
  methods: {
    getDetailInfo() {
      axios
        .get("/api/detail.json", {
          params: {
            id: this.$route.params.id,
          },
        })
        .then(this.handleGetDataSucc);
    },
    handleGetDataSucc(res) {
      res = res.data;
      if (res.ret && res.data) {
        const data = res.data;
        this.sightName = data.sightName;
        this.bannerImg = data.bannerImg;
        this.gallaryImgs = data.gallaryImgs;
        this.list = data.categoryList;
      }
    },
  },

  mounted() {
    this.getDetailInfo();
  },
//   activated() {
//     this.getDetailInfo();
//   },

//   这是在keep alive下，页面进行了缓存，mounted只会执行一次，导致ajax请求后续失效，每次刷新页面仍然进行ajax请求的方法之一,在这个组件中
//   我们使用另外的方法。 在keepalive上写入属性exclude="组件的name"
};
</script>

<style lang="stylus" scoped>
.kong {
  height: 50rem;
}
</style>